package com.jiang.jpa.config.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * \* 作者: jiang
 * \* 时间: 2021/5/29 10:04
 * \* 描述: SwaggerConfig
 * \
 */
@EnableSwagger2WebMvc
@Configuration
public class SwaggerConfig {

    @Value("${spring.application.name}")
    private String serviceName;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jiang"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(serviceName)
                .description(serviceName + "接口文档")
                .termsOfServiceUrl("http://dkreal.cn/")
                .contact(new Contact("jiangshaoneng","",""))
                .version("1.0")
                .build();
    }
}